//package org.lg.filter;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@WebFilter(urlPatterns="/*")
//public class DemoFilter implements Filter {
//    /**
//     * 过滤器的初始化方法
//     * @param filterConfig 可以获取部署描述符文件(web.xml)中分配的过滤器初始化参数。
//     * @throws ServletException
//     */
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        System.out.println("过滤器被创建了");
//    }
//
//    /**
//     *
//     * @param servletRequest 请求
//     * @param servletResponse 响应
//     * @param filterChain  链条，对过滤器进行阻止和放行
//     * @throws IOException
//     * @throws ServletException
//     */
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        System.out.println("过滤器被执行了");
//        servletResponse.setContentType("text/html,charset=utf-8");
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        response.addHeader("Access-Control-Allow-Origin","*");
//        String referer = request.getHeader("referer");
//        System.out.println(referer);
//        filterChain.doFilter(servletRequest,servletResponse);//放行
//    }
//
//    @Override
//    public void destroy() {
//        System.out.println("过滤器被销毁了");
//    }
//}